import axios from "axios"
import { ref } from "vue"

export const useRequest = () => {
  const data = ref(null)
  const loading = ref(false)
  const error = ref(null)
  const request = async (url) => {
    loading.value = true
    try {
      const res = await axios.get(url)
      data.value = res.data
    } catch (err) {
      error.value = err
    } finally {
      loading.value = false
    }
  }
  return { data, loading, error, request }
}
